package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyParkCarParkingVo;
import com.ruoyi.system.bo.ZsyyParkCarParkingQueryBo;
import com.ruoyi.system.bo.ZsyyParkCarParkingAddBo;
import com.ruoyi.system.bo.ZsyyParkCarParkingEditBo;
import com.ruoyi.system.service.IZsyyParkCarParkingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 车辆和车场关系Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "车辆和车场关系控制器", tags = {"车辆和车场关系管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/parkCarParking")
public class ZsyyParkCarParkingController extends BaseController {

    private final IZsyyParkCarParkingService iZsyyParkCarParkingService;

    /**
     * 查询车辆和车场关系列表
     */
    @ApiOperation("查询车辆和车场关系列表")
    @PreAuthorize("@ss.hasPermi('system:parkCarParking:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyParkCarParkingVo> list(@Validated ZsyyParkCarParkingQueryBo bo) {
        return iZsyyParkCarParkingService.queryPageList(bo);
    }

    /**
     * 导出车辆和车场关系列表
     */
    @ApiOperation("导出车辆和车场关系列表")
    @PreAuthorize("@ss.hasPermi('system:parkCarParking:export')")
    @Log(title = "车辆和车场关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyParkCarParkingVo> export(@Validated ZsyyParkCarParkingQueryBo bo) {
        List<ZsyyParkCarParkingVo> list = iZsyyParkCarParkingService.queryList(bo);
        ExcelUtil<ZsyyParkCarParkingVo> util = new ExcelUtil<ZsyyParkCarParkingVo>(ZsyyParkCarParkingVo.class);
        return util.exportExcel(list, "车辆和车场关系");
    }

    /**
     * 获取车辆和车场关系详细信息
     */
    @ApiOperation("获取车辆和车场关系详细信息")
    @PreAuthorize("@ss.hasPermi('system:parkCarParking:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyParkCarParkingVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyParkCarParkingService.queryById(id));
    }

    /**
     * 新增车辆和车场关系
     */
    @ApiOperation("新增车辆和车场关系")
    @PreAuthorize("@ss.hasPermi('system:parkCarParking:add')")
    @Log(title = "车辆和车场关系", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyParkCarParkingAddBo bo) {
        return toAjax(iZsyyParkCarParkingService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改车辆和车场关系
     */
    @ApiOperation("修改车辆和车场关系")
    @PreAuthorize("@ss.hasPermi('system:parkCarParking:edit')")
    @Log(title = "车辆和车场关系", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyParkCarParkingEditBo bo) {
        return toAjax(iZsyyParkCarParkingService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除车辆和车场关系
     */
    @ApiOperation("删除车辆和车场关系")
    @PreAuthorize("@ss.hasPermi('system:parkCarParking:remove')")
    @Log(title = "车辆和车场关系" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyParkCarParkingService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
